package com.gree.controller;

import java.util.List;
import java.io.IOException;
import java.io.PrintWriter;

import com.gree.entity.CmnC006User;
import javax.servlet.http.HttpSession;
import com.gree.entity.TrsT022LoggerRecord;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import or.pagination.MyPager;

import org.springframework.stereotype.Controller;

 
import com.gree.service.ITrsT022LoggerRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class LoggerRecordController {

	@Autowired
	private ITrsT022LoggerRecordService loggerRecordService;

	@RequestMapping(value = "/logger/getSearch")
	public String get(TrsT022LoggerRecord record, HttpSession session,HttpServletResponse response, HttpServletRequest request)	throws IOException {
		CmnC006User user = (CmnC006User) session.getAttribute("user");
		if (user != null) {
			return "logger/Logger";
		} else {
			PrintWriter out = response.getWriter();
			out.println("<html>");
			out.println("<script>");
			out.println("window.open ('" + request.getContextPath()+ "/Views/index.jsp','_top')");
			out.println("</script>");
			out.println("</html>");
			return null;
		}
	}

	@RequestMapping(value = "/logger/search")
	public String getSearch(TrsT022LoggerRecord record, HttpSession session,HttpServletResponse response, HttpServletRequest request)throws IOException {
		CmnC006User user = (CmnC006User) session.getAttribute("user");
		if (user != null) {
			record.setHoldUser(user.getUserId());
			List<TrsT022LoggerRecord> loggerRecords = loggerRecordService.getLoggerRecordResult(record);
			MyPager.getPager(loggerRecords, request);
			session.setAttribute("record", record);// 对象
			return "logger/arrayList";
		} else {
			PrintWriter out = response.getWriter();
			out.println("<html>");
			out.println("<script>");
			out.println("window.open ('" + request.getContextPath()+ "/Views/index.jsp','_top')");
			out.println("</script>");
			out.println("</html>");
			return null;
		}
	}
}
